package org.ISCS.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.ISCS.entity.Services;
import org.ISCS.entity.customize.CustomResult;
import org.ISCS.mapper.ServiceMapper;
import org.ISCS.service.ServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
* @author mj
* @description 针对表【service】的数据库操作Service实现
* @createDate 2023-05-24 00:54:14
*/
@Service
public class ServiceServiceImpl extends ServiceImpl<ServiceMapper, Services>
    implements ServiceService{

    @Autowired
    ServiceMapper serviceMapper;
    @Override
    public CustomResult insertByList(Collection<Services> services) {
        CustomResult result;
        if (serviceMapper.insertBatch(services) > 0){
            result = new CustomResult(20000,"Success",null);
        }else {
            result = new CustomResult(40000,"Failed",null);
        }
        return result;
    }

    @Override
    public CustomResult getServicesByProjectId(Long projectId) {
        CustomResult result;
        List<Services> servicesList = serviceMapper.selectAllByAffiliateProjectId(projectId);
        if (servicesList.size() > 0){
            result = new CustomResult(20000,"Success",servicesList);
        }else {
            result = new CustomResult(40000,"find nothing",null);
        }
        return result;
    }
    @Override
    public Services insertService(Services service) {
        int id =  serviceMapper.insert(service);
        service.setId((long) id);
        return service;
    }

    @Override
    public int updateService(Services services) {
        int id =  serviceMapper.updateById(services);
        return id;
    }
}




